import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import elementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import api from './util/api'
import './util/mySessionStorage.js'
import './util/myLocalStorage.js'

import './util/mouseclick'

import 'highlight.js/styles/default.css';

import Hljs from 'highlight.js'

Vue.directive('highlight', function (el) {
  let blocks = el.querySelectorAll('pre code');
  blocks.forEach((block) => {
    Hljs.highlightElement(block)
  })
})

const isDev = process.env.NODE_ENV === 'development'
let baseUrl = mySessionStorage.getItem("baseUrl", isDev ? "http://" + location.hostname + ":8088" : location.origin)

Vue.use(api, {baseUrl: baseUrl})

Vue.use(elementUI, {size: "mini"})
Vue.config.productionTip = false

document.addEventListener('keydown', e => {
  if (e.code === 'KeyS' && e.ctrlKey) {
    e.preventDefault()
  }
})
Vue.prototype.$api.getXtInfo().then(xtInfo => {
  store.commit("setXtInfo", xtInfo)
  document.title += `-${xtInfo.gzyqVersion}`
})
Vue.prototype.$listToTree = (data, id, pid) => {
  let itemObj = {}
  for (let item of data) {
    item.children = []
    itemObj[item[id]] = item
  }
  let arr = []
  for (let item of data) {
    if (itemObj[item[pid]]) {
      itemObj[item[pid]].children.push(item)
    } else {
      arr.push(item)
    }
  }
  return arr
}


// (async () => {
//   let url = "http://192.168.3.194/bd-service/api/model/getModelCategoryList?xtbz=TYAK&dwbm=100000"
//   let res = await axios.get(url)
//   let arr = []
//   for (const item of res) {
//     let newUrl = `http://192.168.3.194/bd-service/api/model/getModelList?xtbz=TYAK&mxflbm=${item.mxflbm}`
//     let newRes = await axios.get(newUrl)
//     for (const newRe of newRes) {
//       arr.push({
//         mxmc: newRe.mxmc,
//         mxbm: newRe.mxbm,
//       })
//     }
//   }
//   console.log(JSON.stringify(arr))
// })();


new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
